const {
  merge
} = require('webpack-merge')
const path = require('path')
const webpackCommon = require('./webpack.common')
const HtmlWebpackPlugin = require('Html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')

module.exports = merge(webpackCommon, {
  mode: 'production',
  devtool: 'none',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: path.join('static', 'js/[name].[chunkhash:8].js'),
    publicPath: ''
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: path.join('static', 'css/[name].[contenthash:8].css'),
    }),
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: 'public/index.html',
      inject: true,
      title: '作业2-2',
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeAttributeQuotes: true
      },
      templateParameters: {
        BASE_URL: ''
      }
    }),
    new CopyWebpackPlugin({
      patterns: [{
        from: 'public/favicon.ico',
        to: 'favicon.ico'
      }]
    })
  ]
})